*** Paper: 			Does The World Trade Organization Enable Biosecurity and Trade for Importers and Exporters?
*** Authors: Linda Fernandez and Monica Das
*** Date:    		November 9, 2023
*** Last updated:   February 21, 2024
*** Description:	STATA codes for Tables 7 - 9 in the paper

******************************************************
**** TABLE 7 - 9  (by geographical regions) 
*******************************************************
///Download STATA file "wd.dta" from the Harvard Dataverse  
///Change directory to appropriate folder
//import STATA dataset "wd.dta" 
use "wd.dta", clear

///(Diversification)//////////////////////////////////
asdoc, row(\i, \i, \i) save(table 7) fs(16) font(Times New Roman) title(Random Coefficients Model Estimates: group-id region) replace


xtrc AgrExport TACommlag Manu_sh lnRGDP, i( region) betas

/////// TABLE  7    ///////////////////
xtrc AgrExport TACommlag Manu_sh lnRGDP Diversification_Int resid_Div, i( region) betas vce(bootstrap, seed(101016) reps(1000) dots(100))

matrix beta = e(beta_ps)
matrix B = beta'
matrix list B


matrix beta_se= e(V_ps)
matrix T = e(V_ps)'
		
matrix C = J(36,4,0)

foreach i in 1 8 15 22 29 {
	foreach j in 1 2 3 4 {
		 matrix C[`i',`j']= sqrt(T[`i',`j'])
	}
}
matrix list C

matrix result_int = (B[1,1], B[1,2], B[1,3], B[1,4]\C[1,1], C[1,2], C[1,3], C[1,4]\ B[2,1], B[2,2], B[2,3], B[2,4]\C[8,1], C[8,2], C[8,3], C[8,4]\ B[3,1], B[3,2], B[3,3], B[3,4]\C[15,1], C[15,2], C[15,3], C[15,4]\B[4,1], B[4,2], B[4,3], B[4,4]\C[22,1], C[22,2], C[22,3], C[22,4] \B[5,1], B[5,2], B[5,3], B[5,4]\C[29,1], C[29,2], C[29,3], C[29,4] \B[6,1], B[6,2], B[6,3], B[6,4]\C[36,1], C[36,2], C[36,3], C[36,4])

asdoc, row(\i, \i, \i, \i, \i) save(table 7) fs(16) font(Times New Roman) title(\)
asdoc, row(Table, \i, \i, \i, \i) save(table 7) fs(8) font(Times New Roman) title(\) 	
asdoc, row(\i, EWS Asia, Europe Central Asia, Latin America Carribean, Middle East Africa) save(table 7) fs(8) font(Times New Roman) title(\)
asdoc wmat, matrix(result_int) rnames(TACommlag se Manu_sh se lnRGDP se Diversification_Int se Residual se _cons se) cnames(AgrExportit AgrExportit AgrExportit AgrExportit) dec(2) fs(8) save(table 7) font(Times New Roman) title(\)


////(Duration)///////////////////////////////////////

/////// TABLE  8    ///////////////////
asdoc, row(\i, \i, \i) save(table 8) fs(16) font(Times New Roman) title(Random Coefficients Model Estimates: group-id region) replace

xtrc AgrExport TAduration Manu_sh lnRGDP Duration_Int resid_Dur, i( region) betas vce(bootstrap, seed(101016) reps(1000) dots(100))

matrix beta = e(beta_ps)
matrix B = beta'
matrix list B


matrix beta_se= e(V_ps)
matrix T = e(V_ps)'
			
matrix C = J(36,4,0)

foreach i in 1 8 15 22 29 {
	foreach j in 1 2 3 4{
		 matrix C[`i',`j']= sqrt(T[`i',`j'])
	}
}
        
matrix list C


matrix result_int = (B[1,1], B[1,2], B[1,3], B[1,4]\C[1,1], C[1,2], C[1,3], C[1,4]\ B[2,1], B[2,2], B[2,3], B[2,4]\C[8,1], C[8,2], C[8,3], C[8,4]\ B[3,1], B[3,2], B[3,3], B[3,4]\C[15,1], C[15,2], C[15,3], C[15,4]\B[4,1], B[4,2], B[4,3], B[4,4]\C[22,1], C[22,2], C[22,3], C[22,4]\B[5,1], B[5,2], B[5,3], B[5,4]\C[29,1], C[29,2], C[29,3], C[29,4] \B[6,1], B[6,2], B[6,3], B[6,4]\C[36,1], C[36,2], C[36,3], C[36,4])

asdoc, row(\i, \i, \i, \i, \i) save(table 8) fs(16) font(Times New Roman) title(\)
asdoc, row(Table, \i, \i, \i, \i) save(table 8) fs(8) font(Times New Roman) title(\) 	
asdoc, row(\i, EWS Asia, Europe Central Asia, Latin America Carribean, Middle East Africa) save(table 8) fs(8) font(Times New Roman) title(\)
asdoc wmat, matrix(result_int) rnames(TAduration se Manu_sh se lnRGDP se Duration_Int se Residual se _cons se) cnames(AgrExportit AgrExportit AgrExportit AgrExportit) dec(2) fs(8) save(table 8) font(Times New Roman) title(\)



//////////////////////////////////////////////////
/////////////// (Value)
//////////////////////////////////////////////////


/////// TABLE  9    ///////////////////

xtrc AgrExport lnTAvalue Manu_sh RGDP Value_Int resid_Value, i( region) betas vce(bootstrap, reps(1000) seed(101016) dots(100))

matrix beta = e(beta_ps)
matrix B = beta'
matrix list B

matrix beta_se= e(V_ps)
matrix T = e(V_ps)'
			
matrix C = J(36,4,0)

foreach i in 1 8 15 22 29 {
	foreach j in 1 2 3 4 {
		 matrix C[`i',`j']= sqrt(T[`i',`j'])
	}
}
        
matrix list C

matrix result_int = (B[1,1], B[1,2], B[1,3], B[1,4]\C[1,1], C[1,2], C[1,3], C[1,4]\ B[2,1], B[2,2], B[2,3], B[2,4]\C[8,1], C[8,2], C[8,3], C[8,4]\ B[3,1], B[3,2], B[3,3], B[3,4]\C[15,1], C[15,2], C[15,3], C[15,4]\B[4,1], B[4,2], B[4,3], B[4,4]\C[22,1], C[22,2], C[22,3], C[22,4]\B[5,1], B[5,2], B[5,3], B[5,4]\C[29,1], C[29,2], C[29,3], C[29,4] \B[6,1], B[6,2], B[6,3], B[6,4]\C[36,1], C[36,2], C[36,3], C[36,4])

asdoc, row(\i, \i, \i) save(table 9) fs(16) font(Times New Roman) title(Random Coefficients Model Estimates: group-id region) replace

asdoc, row(\i, \i, \i, \i) save(table 9) fs(16) font(Times New Roman) title(\)
asdoc, row(Table, \i, \i, \i) save(table 9) fs(8) font(Times New Roman) title(\) 	
asdoc, row(\i, EWS Asia, C Asia & Europe Central Asia, Latin America Carribean, Middle East Africa) save(table 9) fs(8) font(Times New Roman) title(\)
asdoc wmat, matrix(result_int) rnames(lnTAvalue se Manu_sh se lnRGDP se Value_Int se Residual se _cons se) cnames(AgrExportit AgrExportit AgrExportit AgrExportit) dec(2) fs(8) save(table 9) font(Times New Roman) title(\)


